<?php

/**
 * ECSHOP 文章分类
 * ============================================================================
 * * 版权所有 2005-2012 上海商派网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.ecshop.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: liubo $
 * $Id: article_cat.php 17217 2011-01-19 06:29:08Z liubo $
*/


define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

if ((DEBUG_MODE & 2) != 2)
{
    $smarty->caching = true;
}

/* 清除缓存 */
clear_cache_files();

/*------------------------------------------------------ */
//-- INPUT
/*------------------------------------------------------ */

/* 获得指定的分类ID */
if (!empty($_GET['id']))
{
    $cat_id = intval($_GET['id']);
}
elseif (!empty($_GET['category']))
{
    $cat_id = intval($_GET['category']);
}
else
{
    ecs_header("Location: ./\n");

    exit;
}

//操作
$act = !empty($_GET['act'])?$_GET['act']:"";

/* 获得当前页码 */
$page   = !empty($_REQUEST['page'])  && intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;

/*------------------------------------------------------ */
//-- PROCESSOR
/*------------------------------------------------------ */

/* 获得页面的缓存ID */
$cache_id = sprintf('%X', crc32($cat_id . '-' . $page . '-' . $_CFG['lang']));
if($cat_id>0)
{
   $cat = get_article_parent_cats($cat_id);
   $length = count($cat);
    if($length==2){
        $parent_id = $cat[1]['cat_id'];
    }else{
        $parent_id = $cat[0]['cat_id'];
    }
}
$arrTemplate = array(4,5,6,7,17);
if(in_array($parent_id,$arrTemplate)){
    $template = 'article_channel.dwt';
}
else{
    $template = 'article_pro.dwt';
}

if (!$smarty->is_cached($template, $cache_id))
{
    /* 如果页面没有被缓存则重新获得页面的内容 */
    assign_template('a', array($cat_id));
    $position = assign_ur_here($cat_id);
    $smarty->assign('page_title',           $position['title']);     // 页面标题
    $smarty->assign('ur_here',              $position['ur_here']);   // 当前位置
    $smarty->assign('helps',                get_shop_help());        // 网店帮助

    /* Meta */
    $meta = $db->getRow("SELECT keywords, cat_desc FROM " . $ecs->table('article_cat') . " WHERE cat_id = '$cat_id'");

    if ($meta === false || empty($meta))
    {
        /* 如果没有找到任何记录则返回首页 */
        ecs_header("Location: ./\n");
        exit;
    }

    $smarty->assign('keywords',    htmlspecialchars($meta['keywords']));
    $smarty->assign('description', htmlspecialchars($meta['cat_desc']));
    $smarty->assign('parent_id',$parent_id);
    $smarty->assign('cat_id',    $cat_id);
    $smarty->assign('act',$act);

    //获取文章分类的子栏目
    $smarty->assign('article_soncat',get_article_cat($parent_id));
    //获取栏目简介内容
    if($cat_id==9){
        $sql = 'SELECT content FROM '.$GLOBALS['ecs']->table('article').' WHERE article_id = 7';
        $content = $GLOBALS['db']->getOne($sql);
        $smarty->assign('contents',$content);
        $smarty->assign('huaxu',get_articles(5,1,0,6));
    }
    //获取推荐美人信息
    elseif($cat_id == 5){
        if($act != 'more')
        {
            //推荐美女相册
            $smarty->assign('rec_girls1',get_articles(5,1,0,1));
            $smarty->assign('rec_girls2',get_articles(5,1,1,2));
            $smarty->assign('rec_girls3',get_articles(5,1,3,2));
            //普通美女相册列表
            $smarty->assign('girl_list',get_articles(5,0,0,5));
        }
        else
        {
            /* 获得当前页码 */
            $page   = !empty($_REQUEST['page'])  && intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;

            /* 获得文章总数 */
            $size   = isset($_CFG['article_page_size']) && intval($_CFG['article_page_size']) > 0 ? intval($_CFG['article_page_size']) : 20;
            $count  = get_article_count($cat_id);
            $pages  = ($count > 0) ? ceil($count / $size) : 1;

            if ($page > $pages)
            {
                $page = $pages;
            }
            $pager['search']['id'] = $cat_id;

            $smarty->assign('girl_list',    get_cat_articles($cat_id, $page, $size ,$keywords));
            /* 分页 */
            assign_pager('article_cat', $cat_id, $count, $size, '', '', $page, '','more');
        }
    }
    //玉美人配饰
    elseif($cat_id == 6){
        $smarty->assign("peishi",get_articles($cat_id,1,0,10));
    }
    //玉器咨询
    elseif($cat_id ==7){
        /* 获得当前页码 */
        $page   = !empty($_REQUEST['page'])  && intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;

        /* 获得文章总数 */
        $size   = 1;
        $count  = get_article_count($cat_id);
        $pages  = ($count > 0) ? ceil($count / $size) : 1;

        if ($page > $pages)
        {
            $page = $pages;
        }
        $pager['search']['id'] = $cat_id;

        $smarty->assign('list_news',    get_cat_articles($cat_id, $page, $size ,$keywords,true));
        /* 分页 */
        assign_pager('article_cat', $cat_id, $count, $size, '', '', $page, '');
    }
    //玉美人资讯
    elseif($cat_id ==17){
        /* 获得当前页码 */
        $page   = !empty($_REQUEST['page'])  && intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;

        /* 获得文章总数 */
        $size   = 1;
        $count  = get_article_count($cat_id);
        $pages  = ($count > 0) ? ceil($count / $size) : 1;

        if ($page > $pages)
        {
            $page = $pages;
        }
        $pager['search']['id'] = $cat_id;

        $smarty->assign('list_news',    get_cat_articles($cat_id, $page, $size ,$keywords,true));
        /* 分页 */
        assign_pager('article_cat', $cat_id, $count, $size, '', '', $page, '');
    }
    //栏目主持
    elseif($cat_id==12){
        $sql = 'SELECT content FROM '.$GLOBALS['ecs']->table('article').' WHERE article_id = 10';
        $content = $GLOBALS['db']->getOne($sql);
        $smarty->assign('contents',$content);
    }
    //节目内容
    elseif($cat_id==10){
        /* 获得当前页码 */
        $page   = !empty($_REQUEST['page'])  && intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;

        /* 获得文章总数 */
        $size   = isset($_CFG['article_page_size']) && intval($_CFG['article_page_size']) > 0 ? intval($_CFG['article_page_size']) : 20;
        $count  = get_article_count($cat_id);
        $pages  = ($count > 0) ? ceil($count / $size) : 1;

        if ($page > $pages)
        {
            $page = $pages;
        }
        $pager['search']['id'] = $cat_id;

        $smarty->assign('programs',    get_cat_articles($cat_id, $page, $size ,$keywords));
        /* 分页 */
        assign_pager('article_cat', $cat_id, $count, $size, '', '', $page, $goon_keywords);
    }
    //节目剧照
    elseif($cat_id==11){
        /* 获得当前页码 */
        $page   = !empty($_REQUEST['page'])  && intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;

        /* 获得文章总数 */
        $size   = isset($_CFG['article_page_size']) && intval($_CFG['article_page_size']) > 0 ? intval($_CFG['article_page_size']) : 20;
        $count  = get_article_count($cat_id);
        $pages  = ($count > 0) ? ceil($count / $size) : 1;

        if ($page > $pages)
        {
            $page = $pages;
        }
        $pager['search']['id'] = $cat_id;
        $smarty->assign('photos',    get_cat_articles($cat_id, $page, $size ,$keywords));
        /* 分页 */
        assign_pager('article_cat', $cat_id, $count, $size, '', '', $page, $goon_keywords);
    }
    //节目美人
    elseif($cat_id==13){
        /* 获得当前页码 */
        $page   = !empty($_REQUEST['page'])  && intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;

        /* 获得文章总数 */
        $size   = isset($_CFG['article_page_size']) && intval($_CFG['article_page_size']) > 0 ? intval($_CFG['article_page_size']) : 20;
        $count  = get_article_count($cat_id);
        $pages  = ($count > 0) ? ceil($count / $size) : 1;

        if ($page > $pages)
        {
            $page = $pages;
        }
        $pager['search']['id'] = $cat_id;
        $smarty->assign('pretygirl',    get_cat_articles($cat_id, $page, $size ,$keywords));
        /* 分页 */
        assign_pager('article_cat', $cat_id, $count, $size, '', '', $page, $goon_keywords);
    }
    //节目嘉宾
    elseif($cat_id==14){
        /* 获得当前页码 */
        $page   = !empty($_REQUEST['page'])  && intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;

        /* 获得文章总数 */
        $size   = isset($_CFG['article_page_size']) && intval($_CFG['article_page_size']) > 0 ? intval($_CFG['article_page_size']) : 20;
        $count  = get_article_count($cat_id);
        $pages  = ($count > 0) ? ceil($count / $size) : 1;

        if ($page > $pages)
        {
            $page = $pages;
        }
        $pager['search']['id'] = $cat_id;
        $smarty->assign('guests',    get_cat_articles($cat_id, $page, $size ,$keywords));
        /* 分页 */
        assign_pager('article_cat', $cat_id, $count, $size, '', '', $page, $goon_keywords);
    }

    //藏家故事
    elseif($cat_id==15){
        /* 获得当前页码 */
        $page   = !empty($_REQUEST['page'])  && intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;

        /* 获得文章总数 */
        $size   = isset($_CFG['article_page_size']) && intval($_CFG['article_page_size']) > 0 ? intval($_CFG['article_page_size']) : 20;
        $count  = get_article_count($cat_id);
        $pages  = ($count > 0) ? ceil($count / $size) : 1;

        if ($page > $pages)
        {
            $page = $pages;
        }
        $pager['search']['id'] = $cat_id;
        $smarty->assign('collecters',    get_cat_articles($cat_id, $page, $size ,$keywords));
        /* 分页 */
        assign_pager('article_cat', $cat_id, $count, $size, '', '', $page, $goon_keywords);
    }
    //精彩花絮
    elseif($cat_id==16){
        $smarty->assign("jchx_single",get_articles(16,1,0,1));
        $smarty->assign("jchx_list",get_articles(16,1,1,5));
    }
    //视频剪辑
    elseif($cat_id==22){
        /* 获得当前页码 */
        $page   = !empty($_REQUEST['page'])  && intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;

        /* 获得文章总数 */
        $size   = isset($_CFG['article_page_size']) && intval($_CFG['article_page_size']) > 0 ? intval($_CFG['article_page_size']) : 20;
        $count  = get_article_count($cat_id);
        $pages  = ($count > 0) ? ceil($count / $size) : 1;

        if ($page > $pages)
        {
            $page = $pages;
        }
        $pager['search']['id'] = $cat_id;
        $smarty->assign('videos',    get_cat_articles($cat_id, $page, $size ,$keywords));
        /* 分页 */
        assign_pager('article_cat', $cat_id, $count, $size, '', '', $page, $goon_keywords);
    }
}

$smarty->display($template, $cache_id);

?>